package com.ryan.demo.grpc.server.controller;


import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import com.ryan.demo.grpc.api.AckReceiptData;
import com.ryan.demo.grpc.server.service.SpecifyPubService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author MRyan
 */
@RestController
@Slf4j
public class GrpcDemoController {

    @Resource
    private SpecifyPubService specifyPubService;

    @GetMapping("/publishSpecify")
    public String publishSpecify() throws InvalidProtocolBufferException {
        log.info("Do publishSpecify");
        AckReceiptData ackReceiptRes = specifyPubService.receiveEvent();
        return JsonFormat.printer().print(ackReceiptRes);
    }
}
